<?php
class DefaultController extends CController {
	
	public $breadcrumbs;
	
	public $layout='/layouts/column1';
	
	public function actionIndex() {
		$model = new DbmTableInfo('search');
		$model->unsetAttributes();
		if(isset($_GET['DbmTableInfo'])) {
			$model->attributes = $_GET['DbmTableInfo'];
		}
		$this->render('index', array(
			'model' => $model,
			'data' => $model->search(),
		));
	}
	
	public function actionRefresh($table_name = null) {
		DbMonitorHelper::getInstance()->refresh($table_name);
		if($table_name) {
			$this->redirect($this->createUrl('diffDetail', array(
				'table_name' => $table_name,
			)));
		} else {
			$this->redirect(array('info'));
		}
	}
	
	public function actionUpdateRemark($id) {
		Yii::import('lib.helpers.CControllerHelper');
		if(isset($_POST['DbmHistorySearch']) && ($model = DbMonitor::model()->findByPk($id))) {
			$model->attributes = $_POST['DbmHistorySearch'];
			$model->save();
		}
		CControllerHelper::redirectReferrer();
	}
	
	public function actionDiffDetail($table_name) {
		$model = new DbmHistorySearch('search');
		$model->unsetAttributes();
		if(isset($_GET['DbMonitorSearch'])) {
			$model->attributes =$_GET['DbMonitorSearch'];
		}
		$this->render('diff-detail', array(
			'model' => $model,
			'table_name' => $table_name,
			'data' => $model->only($table_name)->desc('create_time')->search(),
		));
	}
}

?>